#ifndef _EFFECT_ENTITY_H_
#define _EFFECT_ENTITY_H_

#include "AbstractEntity.h"
#include "Effect.h"
#include "GameDeviceSingleton.h"

class EffectEntity
{
public:
	bool isDone;

	EffectEntity(Effect* effectData, double x, double y)
	{
		isDone = false;

		_x = x;
		_y = y;
		_repeat = effectData->repeatTime;
		_initSprites(effectData->spriteId, effectData->framerate);

		_repeatTime = 0;
	}

	virtual void update(long time)
	{
  		if(_sprite->endOfSheet())
		{
			_repeatTime++;
		}
		if(_sprite->currentIndex() == _sprite->getStartIndex() && _repeatTime > _repeat)
		{
			isDone = true;
			return;
		}
		_sprite->Next();
	}

	virtual void draw(long time)
	{
		if(_sprite->currentIndex() == _sprite->getStartIndex() && _repeatTime > _repeat)
		{
			return;
		}
		_sprite->Render(_x, _y);
	}

	~EffectEntity()
	{
	}

private:
	Sprite* _sprite;
	double _x;
	double _y;
	int _repeatTime;
	int _repeat;

	void _initSprites(int SpriteId, int framerate)
	{
		_sprite = new Sprite(*(GameDeviceSingleton::getInstance()->getSpriteHandler()), SpriteId, false, framerate);
	}
};

#endif